/*
* 组件：分页组件
* 
*/
import { Pagination } from 'antd';
import React, { useState } from 'react';
import { pagination } from "@/config";

// css
export default function MyPagination({ curr = 1, total, size = pagination.pageSize, onChange }) {

    const [_curr, setCurr] = useState(curr);
    const [nTotal, setNTotal] = useState(total);

    if (total !== nTotal) {
        setCurr(1);
        setNTotal(total);
    }

    if (!nTotal) {
        return null
    }

    return (
        <div className="list-pagination">
            <Pagination
                total={nTotal}
                showTotal={total => `共${total}条信息`}
                pageSize={size}
                current={_curr}
                onChange={(curr) => {
                    setCurr(curr);
                    onChange(curr);
                }}
            />
        </div>
    )
}